import {ADDRESS, ISSHOW, INVITER} from "../mutations_type.js"
import {connect} from '@/api/user'

const user = {
    state: {
        isShow: false,
        token: null,
        address: null,
        wallet: null,
        account: null,
        inviter: null
    },
    mutations: {
        [INVITER](state, payload) {
            state.inviter = payload;
        },
        [ADDRESS](state, payload) {
            state.address = payload.address;
            // state.inviter=payload.code;
            let data = {address: state.address, "inviter": state.inviter}
            connect(data).then(res => {
                // console.log(res)
                state.account = res.account;
                state.wallet = res.wallet;
                state.token = res.token;
            })
        },
        setaccount(state, payload) {
            state.account = payload.account;
            state.wallet = payload.wallet;
        },
        [ISSHOW](state, payload) {
            state.isShow = payload
        }
    },
    getters: {},
    actions: {
        setcode({commit}, code) {
            commit('INVITER', code)
        },
        setaddress(
            {
                commit
            }, data
        ) {
            commit('ADDRESS', data)

        },
        setIsShow(
            {
                commit
            }, data
        ) {
            commit('ISSHOW', data)

        }
    },
}
export default user